package com.handycraftz.site.server;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.handycraftz.site.client.rpc.HandyCraftzService;
import com.handycraftz.site.server.beans.MailerDaemon;
import com.handycraftz.site.server.validator.HandyCraftzValidator;

public class HandyCraftzServiceImpl extends RemoteServiceServlet implements HandyCraftzService{

	private static final long serialVersionUID = 1L;

	@SuppressWarnings("finally")
	@Override
	public String contactWithMailerDaemon(String mailSenderName, String mailSubject, String mailBody, String mailSender, String mailRecipient) 
	{
		String mailingStatus = null;
		try
		{
			if(!HandyCraftzValidator.validateNullString(mailSenderName))
			{
				mailingStatus = "e:Your Name is Important for us, Please do Provide it.";
			}
			else if(!HandyCraftzValidator.validateNullString(mailSender))
			{
				mailingStatus = "e:We need Your Email Id for Replying. Please do Provide It.";
			}
			else if(!HandyCraftzValidator.validateNullString(mailSubject))
			{
				mailingStatus = "e:Please add the Subject of Your Message.";
			}
			else if(!HandyCraftzValidator.validateNullString(mailBody))
			{
				mailingStatus = "e:Please add your Valuable Message.";
			}
			else if(!HandyCraftzValidator.validateEmail(mailSender))
			{
				mailingStatus = "e:The Email ID is Invalid, Please Re-Enter.";
			}
			else
			{
				MailerDaemon.sendMail(mailSenderName, mailSubject, mailBody, mailSender, mailRecipient);
				mailingStatus = "s:Thank You for Contacting us. We will get back to you Soon...";
			}
		}
		catch(Exception e)
		{
			mailingStatus = "e:Server Error, Cannot Contact HandyCraftz Team";
			e.printStackTrace();
		}
		finally
		{
			return mailingStatus;
		}
	}

}
